home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
aminet
/
util
/
rexx
/
wbrexx_1_1.lzh
/
pathname.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-05-18
|
2KB
|
81 lines
/** pathname.c
*
* Copyright 1988, W.G.J. Langeveld
* All Rights Reserved
* Freely Distributable
*
* Expand path name given a lock on a file name. Emulates ARP function
* of the same name, which is slightly unreliable.
*
**/
#include <exec/exec.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <functions.h>
#include <stdio.h>
char *index();
#define FIBSIZ ((long) sizeof(struct FileInfoBlock))
int PathName(plock, buffer, n)
struct FileLock *plock;
char *buffer;
int n;
{
struct FileLock *lock, *curdir;
char *temp, *pos;
struct FileInfoBlock *filinf;
lock = NULL;
filinf = NULL;
temp = NULL;
buffer[0] = '\0';
filinf = (struct FileInfoBlock *) AllocMem(FIBSIZ, MEMF_PUBLIC|MEMF_CLEAR);
if (filinf == NULL) goto cleanuplk;
temp = (char *) AllocMem(255L, MEMF_PUBLIC|MEMF_CLEAR);
if (temp == NULL) goto cleanuplk;
if (Examine(plock, filinf) == NULL) goto cleanuplk;
strcpy(buffer, filinf->fib_FileName);
lock = ParentDir(plock);
/*
* Now loop back through the parent directories until root is found.
* Meanwhile, keep track of the names.
*/
while (lock != NULL) {
if (Examine(lock, filinf) == NULL) goto cleanuplk;
strcpy(temp, buffer);
strcpy(buffer, filinf->fib_FileName);
strcat(buffer, "/");
strcat(buffer, temp);
curdir = ParentDir(lock);
UnLock(lock);
lock = curdir;
}
/*
* Now fix up the name
*/
if (pos = index(buffer, '/')) {
*pos = ':';
if (pos == buffer) {
strcpy(temp, "ram");
strcat(temp, buffer);
strcpy(buffer, temp);
}
}
cleanuplk:
if (filinf) FreeMem(filinf, FIBSIZ);
if (temp) FreeMem(temp, 255L);
if (lock) UnLock(lock);
return(strlen(buffer));
}